package io.polly.ldz.reactor;

import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import reactor.core.publisher.SignalType;

import java.io.IOException;
import java.time.Duration;

public class FluxDemo {

    public static void limit(String[] args) {
        Flux.range(1,1000).log()
                .limitRate(100)
                .subscribe();
    }

    public static void main(String[] args) {

        Mono<Integer> mono = Mono.just(1);
        mono.subscribe(System.out::println);

//        SignalType signalType = SignalType.ON_NEXT;

        Flux<Object> emptyFlux = Flux.empty()
                .doOnComplete(()->System.out.println("...."));//有一个信号，此时代表完成信号

        Flux<Integer> flux = Flux.just(1, 2, 3,4,4);


        flux.subscribe(System.out::println);
        flux.subscribe(e->System.out.println("e2="+e));

        Flux<Long> flux2 =Flux.interval(Duration.ofSeconds(1L));
        flux2.subscribe(System.out::println);
        try {
            System.in.read();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}
